//
//  ChooseSexView.m
//  Cycling
//
//  Created by cjg.mini on 2023/3/7.
//

#import "ChooseSexView.h"

@implementation ChooseSexView

+ (ChooseSexView *)chooseSexWith:(UIViewController *)vc Complection:(void(^)(int sex))block {
    ChooseSexView *  inputView;
    inputView = [[ChooseSexView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W - 56, 415)];
    [inputView initUI];
    inputView.complectionBlock = block;
    NSLog(@"%@", NSObject.getKeyWindowRootViewController);
    [NSObject.getKeyWindowRootViewController gq_presentLikeAlertView:inputView];
    NSObject.getKeyWindowRootViewController.gq_enableBlankDismiss = NO;
    
    return inputView;
}

- (void)sure{
    self.complectionBlock(self.sex);
}
- (void)cancle{
    self.complectionBlock(-1);
}
- (void)chooseOtherSex {
    self.sex = -1;
    [self.otherBtn setImage:[UIImage imageNamed:@"image_other_select"] forState:UIControlStateNormal];
    [self.womenBtn setImage:[UIImage imageNamed:@"image_women"] forState:UIControlStateNormal];
    [self.menBtn setImage:[UIImage imageNamed:@"image_men"] forState:UIControlStateNormal];

}
- (void)chooseWomen {
    self.sex = 0;
    [self.otherBtn setImage:[UIImage imageNamed:@"image_other"] forState:UIControlStateNormal];
    [self.womenBtn setImage:[UIImage imageNamed:@"image_women_select"] forState:UIControlStateNormal];
    [self.menBtn setImage:[UIImage imageNamed:@"image_men"] forState:UIControlStateNormal];
}
- (void)chooseMen {
    self.sex = 1;
    
    [self.otherBtn setImage:[UIImage imageNamed:@"image_other"] forState:UIControlStateNormal];
    [self.womenBtn setImage:[UIImage imageNamed:@"image_women"] forState:UIControlStateNormal];
    [self.menBtn setImage:[UIImage imageNamed:@"image_men_select"] forState:UIControlStateNormal];
}
- (void)initUI {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W - 56, 415)];
    view.userInteractionEnabled = YES;
    view.center = self.center;
    [self addSubview:view];
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W - 56, 415)];
    bgImageView.image = [UIImage imageNamed:@"image_sexBg"];
    bgImageView.userInteractionEnabled = YES;
    [view addSubview:bgImageView];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
    [cancleBtn addTarget:self action:@selector(cancle) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn.userInteractionEnabled = YES;
    [view addSubview:cancleBtn];
    [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view.mas_right);
        make.top.equalTo(view.mas_top).offset(47);
        make.width.offset(58);
        make.height.offset(58);
    }];
    
    UILabel *titleL = [[UILabel alloc] init];
    titleL.text = CycLocalizedString(@"Choose gender", @"请选择性别");
    titleL.textColor = COLOR_TOPIC_SELECT;
    titleL.font = [UIFont systemFontOfSize:26];
    titleL.textAlignment = NSTextAlignmentCenter;
    [view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view.mas_top).offset(85);
            make.centerX.equalTo(self.mas_centerX);
    }];
    
    UIButton *womenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [womenBtn setImage:[UIImage imageNamed:@"image_women_select"] forState:UIControlStateNormal];
    [womenBtn addTarget:self action:@selector(chooseWomen) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:womenBtn];
    self.womenBtn = womenBtn;
    [womenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(titleL.mas_bottom).offset(54);
        make.width.offset(80);
        make.height.offset(124);
    }];
    
    UIButton *menBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [menBtn setImage:[UIImage imageNamed:@"image_men"] forState:UIControlStateNormal];
    [menBtn addTarget:self action:@selector(chooseMen) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:menBtn];
    self.menBtn = menBtn;
    [menBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(womenBtn.mas_left).offset(-32);
        make.top.equalTo(titleL.mas_bottom).offset(54);
        make.width.offset(59);
        make.height.offset(124);
    }];
    
    UIButton *otherBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [otherBtn setImage:[UIImage imageNamed:@"image_other"] forState:UIControlStateNormal];
    [otherBtn addTarget:self action:@selector(chooseOtherSex) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:otherBtn];
    self.otherBtn = otherBtn;
    [otherBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(womenBtn.mas_right).offset(32);
        make.top.equalTo(titleL.mas_bottom).offset(54);
        make.width.offset(59);
        make.height.offset(124);
    }];
    
    UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [submitBtn setBackgroundImage:[UIImage imageNamed:@"btn_login"] forState:UIControlStateNormal];
    [submitBtn setTitle:CycLocalizedString(@"Submit", @"提交") forState:UIControlStateNormal];
    [submitBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [submitBtn addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(29);
        make.right.equalTo(view.mas_right).offset(-29);
        make.bottom.equalTo(view.mas_bottom).offset(-28);
        make.height.offset(54);
    }];
}

@end
